﻿
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
namespace KiraSh.ResumeTracker
{
    public class EmailServer
    {
        /// <summary>
        /// username for SMTP server
        /// </summary>
        public string SMTPUserName { get; set; }

        /// <summary>
        /// password for SMTP
        /// </summary> 
        [XmlIgnore]
        public string SMTPPassword { 
            get 
            {
                if (string.IsNullOrEmpty(SMTPPasswordEncrypted))
                {
                    return "";
                }
                
                return Encryption.Decrypt(SMTPPasswordEncrypted);
            }
            set 
            {
                if (string.IsNullOrEmpty(value))
                {
                    SMTPPasswordEncrypted = null;
                    return;
                }

                SMTPPasswordEncrypted = Encryption.Encrypt(value);
            }
        }

        /// <summary>
        /// encrypted password for storing in xml
        /// </summary> 
        public string SMTPPasswordEncrypted { get; set; }

        /// <summary>
        /// indicates if email settings contain full information and can be used to send emails
        /// </summary>
        public bool IsFullySetup { get; set; }

        /// <summary>
        /// name for the server
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// SMTP server adress
        /// </summary>
        public string Server { get; set; }

        /// <summary>
        /// SMTP server port
        /// </summary>
        public uint Port { get; set; }

        /// <summary>
        /// true if SSL should be enabled
        /// </summary>
        public bool SSL { get; set; }

        /// <summary>
        /// email account used for this server
        /// </summary>
        public string EmailFrom { set; get; }

        public override string ToString()
        {
            return this.Name;
        }

        public static List<EmailServer> GetDefaultList()
        {
            List<EmailServer> serverList = new List<EmailServer>();
            serverList.Add(new EmailServer() { Name = "gmail", Server = "smtp.gmail.com", Port = 587, SSL = true, IsFullySetup = false });
            serverList.Add(new EmailServer() { Name = "yahoo", Server = "smtp.mail.yahoo.com", Port = 465, SSL = true, IsFullySetup = false });
            serverList.Add(new EmailServer() { Name = "hotmail", Server = "smtp.live.com", Port = 587, SSL = true, IsFullySetup = false });
            return serverList;
        }
    }
}
